package com.seng.resourcetycoon.gui.controllers;

import com.seng.resourcetycoon.HelloApplication;
import com.seng.resourcetycoon.gui.models.ResourceTower;
import com.seng.resourcetycoon.util.ResourceReader;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;

import java.io.IOException;

public class TowerStoreItemController {

    @FXML
    private HBox content;
    @FXML
    private ImageView image;
    @FXML
    private Label name;
    @FXML
    private Label resourceType;
    @FXML
    private Label capacity;

    @FXML Label level;
    @FXML
    private Label status;

    public TowerStoreItemController(){
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("tower-store-item.fxml"));
        fxmlLoader.setController(this);
        try
        {
            fxmlLoader.load();
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    public void bindData(ResourceTower item) {
        name.setText("name："+item.getName());
        resourceType.setText("resourceType："+item.getResourceType().getDescription());
        capacity.setText("capacity："+ item.getResourceGenerationAmount()+"/"+item.getResourceGenerationInterval()+"s");
        status.setText("status："+item.getState().getDescription());
        level.setText("level："+item.getLevel());

        try{
            Image image1 = new Image(ResourceReader.getResourceAsStream(item.getResourceType().getDescription()+".jpg"));
            image.setImage(image1);
        }catch (Exception e) {
            e.printStackTrace();
        }


    }

    public HBox getContent() {
        return content;
    }
}
